/**
 * 
 */
package com.effectiv.req1.security;

import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import com.effectiv.req1.domain.Lov;
import com.effectiv.req1.domain.User;


/**
 * @author Dhrubo
 *
 */
public abstract class SecurityUtil {
	
	public static User getUserDetails() {
		SecurityContext ctx = SecurityContextHolder.getContext();
		SimpleUserDetails userDetails = null;
		User user = null;
		Object o = ctx.getAuthentication().getPrincipal();
		
		if(o instanceof SimpleUserDetails) {
			userDetails = (SimpleUserDetails) o;
		}
		
		if(userDetails != null){
			user = userDetails.getUser();
		}
		return user;
	}
	
	public static boolean isCompanyAdmin(){
		User user = getUserDetails();
		Lov role = user.getRole();
		return "ROLE_COMPANY_ADMIN".equals(role.getName());
		
	}
}

